package com.baomidou.wechat.mp.apistore.actuator;

import org.apache.commons.lang.StringUtils;

import com.alibaba.fastjson.JSON;
import com.baomidou.wechat.mp.apistore.ApiStoreResult;
import com.baomidou.wechat.mp.apistore.vo.IpVo;

/**
 * IP API 执行 Actuator
 */
public class IpActuator extends ApiStoreActuator<IpVo> {
	private static String API_IP = "apistore/iplookupservice/iplookup?ip=%s";
	private String ip;

	public static void main(String[] args) {
		ApiStoreActuator<IpVo> actuator = new IpActuator("117.89.35.58");
		System.out.println(actuator.execute().toString());
	}

	protected IpActuator() {
	}

	public IpActuator(String ip) {
		this.ip = ip;
	}

	@Override
	public IpVo execute() {
		String json = executeHttpGet(null, API_IP, getIp());
		if (StringUtils.isNotBlank(json)) {
			ApiStoreResult asr = JSON.parseObject(json, ApiStoreResult.class);
			if (asr != null && asr.isOK()) {
				return JSON.parseObject(asr.getRetData(), IpVo.class);
			}
		}
		return null;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

}
